<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>数据</el-breadcrumb-item>
        <el-breadcrumb-item>产品</el-breadcrumb-item>
        <el-breadcrumb-item>搜索下载统计</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
      >
        <!-- 自定义按钮 -->
        <template  slot="menuLeft">
          <el-button
            type="primary"
            icon="el-icon-download"
            size="small"
            plain
            @click="handleExcel()"
            >导出Excel</el-button
          >
        </template>
        <template slot-scope="scope" slot="start_remain">
          {{ scope.row.start_remain }}%
        </template>
        <template slot-scope="scope" slot="add_remain">
          {{ scope.row.add_remain }}%
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { handleExcelCat } from "@/api/exportCommon";
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appStatisticsToLeadBook as baseURL } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        // orderByList:'stats_date&DESC'
          // "statistics_date&DESC,app_version&DESC,total_user_count&DESC",
      },
      option: {
        index: true,
        indexLabel: "编号",
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        excelBtn: false,
        menu: false,
        selection: true,
        border: true,
        column: [
          {
            label: "日期",
            prop: "statistics_date_search",
            type: "daterange",
            search: true,
            hide: true,
          },
          {
            label: "日期",
            prop: "stats_date",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            search: false,
            sortable: true,
          },
          {
            label: "版本",
            prop: "app_version",
            type: "input",
            search: true,
          },
          {
            label: "渠道号",
            prop: "channel_id",
            type: "input",
            search: true,
          },
          {
            label: "下载次数",
            prop: "download_num",
            type: "input",
          },
          {
            label: "导入文件数",
            prop: "to_lead_file_num",
            type: "input",
          },
          {
            label: "下载人数",
            prop: "download_people_num",
            type: "input",
          },
          {
            label: "本地文件阅读次数",
            prop: "file_read_num",
            type: "input",
          },
          {
            label: "本地文件阅读人数",
            prop: "file_read_people_num",
            type: "input",
          },
          {
            label: "本地文件阅读总时长(分钟)",
            prop: "file_read_minute",
            type: "input",
          },
        ],
      },
    };
  },

  methods: {
    //数据导出
    async handleExcel() {
      this.loading = true;
      //处理搜索条件
      let params = { ...this.$refs.crud.searchForm };
      if (params.statistics_date_search.length > 0) {
        params.statistics_date = `${
          params.statistics_date_search.length > 0
            ? "!<>!" +
              params.statistics_date_search[0] +
              "," +
              params.statistics_date_search[1]
            : ""
        }`;
      }
      delete params.statistics_date_search;

      //调用导出接口
      handleExcelCat(
        this.$export,
        baseURL.pageAndParam,
        { ...params, ...this.default },
        "新增阅读概况",
        this.page.total,
        [...this.option.column],
        null
      );
      this.loading = false;
    },
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.pageAndParam,
        { ...this.params, ...this.default },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    } /**刷新 */,
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      params.stats_date = `${
        params.statistics_date_search
          ? "!<>!" + params.statistics_date_search
          : ""
      }`;
      delete params.statistics_date_search;
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>